import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";

import viteSvgLoader from "vite-svg-loader";
import { resolve } from "path";

import pkg from "./package.json";
import { config } from "node:process";

const externalDeps = Object.keys(pkg.dependencies || {});

// https://vitejs.dev/config/
export default defineConfig({
	plugins: [vue(), vueJsx(), viteSvgLoader()],
	resolve: {
		alias: {
			"~": fileURLToPath(new URL("./packages", import.meta.url)),
		},
	},
	css: {
		/* CSS 预处理器 */
		preprocessorOptions: {
			scss: {
				additionalData: '@import "~/styles/index.scss";',
			},
		},
	},
	build: {
		lib: {
			entry: resolve(__dirname, "packages/index.ts"),
			name: "gview-next",
			fileName: "index",
			formats: ["es"],
		},
		rollupOptions: {
			external: externalDeps,
			output: {
				globals: {
					vue: "Vue",
				},
				exports: "named",
			},
		},
	},
});
